package _interview150;

import java.util.HashMap;
import java.util.Map;

/**
 * 205. 同构字符串
 */
public class No205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> s2t = new HashMap<>(), t2s = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char sC = s.charAt(i), tC = t.charAt(i);
            if (s2t.containsKey(sC) && s2t.get(sC) != tC) return false;
            if (t2s.containsKey(tC) && t2s.get(tC) != sC) return false;
            s2t.put(sC, tC);
            t2s.put(tC, sC);
        }
        return true;
    }
}
